package com.sunny.file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NioFile {

    private static final int MAX = 1024;

    public static void main(String[] args) {

        File file = new File("aaa");
        try {
            FileInputStream fis = new FileInputStream(file);
            FileChannel fc = fis.getChannel();
            ByteBuffer buffer = ByteBuffer.allocate(MAX);
            int res;
            while ((res = fc.read(buffer)) != -1){
                buffer.flip();
                String r = new String(buffer.array());
                System.out.println(r);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
